﻿/*=============================================================================================
	TASK 10:                                                                            {Arrays}
    Write a program that finds in given array of integers a sequence of given sum S (if present).
    Example: {4, 3, 1, 4, 2, 5, 8}, S=11 => {4, 2, 5}
==============================================================================================*/

using System;

class Program
{
    static void Main()
    {
        int[] arr = { 4, 3, 1, 4, 2, 5, 8 };

        //int[] arr = { 1, 2, 3, 4 };
        int n = arr.Length;
        int start=0;
        int end=0;
        int sum = 0;
        int searchSum=0;

        for (int i = 0; i < n; i++)
        {
            for (int j = 0; j < n; j++)
            {
                if (i + j < n)
                {
                    sum = sum + arr[i + j];
                    if (sum == 11)
                    {
                        start = i;
                        end = i + j;
                        searchSum=sum;
                    }
                }
            }
            sum = 0;
        }
        Console.WriteLine("sum={0}", searchSum);
        for (int i = start; i <= end; i++)
        {
            Console.Write(arr[i]+"");
        }
        Console.WriteLine();
        //int n = 4;
        //int value = 1;
        //int sum = 0; 

        //for (int i = 0; i < n; i++)
        //{
        //    for (int j = 0; j <= n; j++)
        //    {
        //        sum = sum + 1;
        //        Console.Write(sum);
        //    }
        //    Console.WriteLine();
        //    sum = 0;
        //}
    }
}

